package cn.android.x.parent;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.sinothk.dialog.loading.LoadingDialog;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

public abstract class AppBaseFragment extends Fragment {

    @Override
    public void onDestroy() {
        super.onDestroy();

        EventBus.getDefault().unregister(this);

        if (loadingDialog != null) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        EventBus.getDefault().register(this);
    }

    private LoadingDialog loadingDialog;

    public void showLoadingDialog(String msg) {
        loadingDialog = new LoadingDialog(getActivity());
        loadingDialog.show(false, msg);
    }

    public void hideLoadingDialog() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
    }

    public abstract void updateAvatarView(String filePath);
}
